package com.xxx.config;

import java.util.Arrays;

import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.alibaba.druid.support.http.StatViewServlet;
import com.alibaba.druid.support.http.WebStatFilter;

/**
 * @ClassName: DruidConfig 
 * @Description: druid监控配置
 */
@Configuration
public class DruidConfig {
	
	@Bean
	public ServletRegistrationBean druidServlet() {
		ServletRegistrationBean druid = new ServletRegistrationBean();
		druid.setServlet(new StatViewServlet());
		//druid.addInitParameter("allow","127.0.0.1"); //白名单
		//druid.addInitParameter("deny",""); 		 //黑名单 
		druid.addUrlMappings("/druid/*");
		druid.addInitParameter("loginUsername", "admin");
		druid.addInitParameter("loginPassword", "123456");
		return druid;
	}
	
	@Bean
	public FilterRegistrationBean filterRegistrationBean(){
		FilterRegistrationBean fitler = new FilterRegistrationBean();
		fitler.setFilter(new WebStatFilter());
		fitler.setUrlPatterns(Arrays.asList("/*"));
		fitler.addInitParameter("exclusions", "*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*");
		return fitler;
	}
}
